package cate.game.role.pvp.gradepvp;

import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;
import org.apache.commons.collections4.MapUtils;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class GradePvpMark {
    @NoteField(value = "星级")
    public int star;

    @NoteField(value = "最大星级")
    public int maxStar;

    @NoteField(value = "常规赛胜场")
    public int winTimes;

    @NoteField(value = "常规赛挑战次数")
    public int fightTimes;

    @NoteField(value = "王者赛胜场")
    public int kingWinTimes;

    @NoteField(value = "王者赛挑战次数")
    public int kingFightTimes;

    @NoteField(value = "最大伤害")
    public long maxDamage;

    @NoteField(value = "最大连胜次数")
    public int serialWinTimes;

    @NoteField(value = "当前连胜次数")
    public int curSerialWinTimes;

    @NoteField("当前连败次数")
    public int curSerialLoseTimes;

    @NoteField(value = "mvp英雄次数")
    @JsonIgnore
    public Map<Integer, Integer> mvpHero;

    @NoteField(value = "mvp英雄id")
    public int mvpHeroId;

    @NoteField("最高排名")
    public int rank;

    public GradePvpMark() {

    }

    public void initialize() {
        if (mvpHero == null) {
            mvpHero = new HashMap<>();
        }
    }

    public void calcMvpHeroTid() {
        if (MapUtils.isNotEmpty(mvpHero)) {
            mvpHeroId =
                    mvpHero.keySet().stream()
                            .sorted(Comparator.comparingInt(key -> mvpHero.get(key)).reversed())
                            .collect(Collectors.toList())
                            .get(0);
        } else {
            mvpHeroId = 0;
        }
    }

    public void clearMark() {
        this.winTimes = 0;
        this.fightTimes = 0;
        this.kingWinTimes = 0;
        this.kingFightTimes = 0;
        this.maxDamage = 0;
        this.serialWinTimes = 0;
        this.mvpHero.clear();
        this.mvpHeroId = 0;
        this.curSerialWinTimes = 0;
        this.curSerialLoseTimes = 0;
        this.rank = -1;
    }
}
